package org.budo.graph.druid.dubbo.filter;

import com.alibaba.druid.filter.stat.StatFilterContextListenerAdapter;
import com.alibaba.druid.support.http.stat.WebRequestStat;

/**
 * @author limingwei
 * @date 2016年6月7日 下午3:02:45
 * 
 * @see com.alibaba.druid.support.http.AbstractWebStatImpl.WebStatFilterContextListener
 */
public class BudoGraphDruidWebStatFilterContextListener extends StatFilterContextListenerAdapter {
    public void addUpdateCount(int updateCount) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.addJdbcUpdateCount(updateCount);
        }
    }

    public void addFetchRowCount(int fetchRowCount) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.addJdbcFetchRowCount(fetchRowCount);
        }
    }

    public void executeBefore(String sql, boolean inTransaction) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcExecuteCount();
        }
    }

    public void executeAfter(String sql, long nanos, Throwable error) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.addJdbcExecuteTimeNano(nanos);
            if (error != null) {
                reqStat.incrementJdbcExecuteErrorCount();
            }
        }
    }

    public void commit() {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcCommitCount();
        }
    }

    public void rollback() {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcRollbackCount();
        }
    }

    public void pool_connect() {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcPoolConnectCount();
        }
    }

    public void pool_close(long nanos) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcPoolCloseCount();
        }
    }

    public void resultSet_open() {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcResultSetOpenCount();
        }
    }

    public void resultSet_close(long nanos) {
        WebRequestStat reqStat = WebRequestStat.current();
        if (reqStat != null) {
            reqStat.incrementJdbcResultSetCloseCount();
        }
    }
}